package com.ruoyi.buss.grid.sq.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ruoyi.system.api.model.LoginUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.ruoyi.buss.grid.sq.domain.DataWgWgsqSqgl;
import com.ruoyi.buss.grid.sq.mapper.DataWgWgsqSqglMapper;
import com.ruoyi.buss.grid.sq.service.IDataWgWgsqSqglService;
import com.ruoyi.common.core.utils.DateUtils;

/**
 * 网格社区管户Service业务层处理
 * 
 * @author sxy
 * @date 2021-07-16
 */
@Service
public class DataWgWgsqSqglServiceImpl implements IDataWgWgsqSqglService 
{
    @Autowired
    private DataWgWgsqSqglMapper dataWgWgsqSqglMapper;

    /**
     * 查询网格社区管户
     * 
     * @param id 网格社区管户ID
     * @return 网格社区管户
     */
    @Override
    public DataWgWgsqSqgl selectDataWgWgsqSqglById(String id)
    {
        return dataWgWgsqSqglMapper.selectDataWgWgsqSqglById(id);
    }

    /**
     * 查询网格社区管户列表
     * 
     * @param dataWgWgsqSqgl 网格社区管户
     * @return 网格社区管户
     */
    @Override
    public List<DataWgWgsqSqgl> selectDataWgWgsqSqglList(DataWgWgsqSqgl dataWgWgsqSqgl,LoginUser userInfo)
    {
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();
        //如果是admin用户不做处理 不是管理员或总行的根据机构号查询
        if(userInfo.getRoles().contains("zhhz")){
            dataWgWgsqSqgl.setOrgId(orgId);
        } else if(userInfo.getRoles().contains("common")){
            dataWgWgsqSqgl.setOrgId(orgId);
        }
        return dataWgWgsqSqglMapper.selectDataWgWgsqSqglList(dataWgWgsqSqgl);
    }

    /**
     * 新增网格社区管户
     * 
     * @param dataWgWgsqSqgl 网格社区管户
     * @return 结果
     */
    @Override
    public int insertDataWgWgsqSqgl(DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        dataWgWgsqSqgl.setCreateTime(DateUtils.getNowDate());
        return dataWgWgsqSqglMapper.insertDataWgWgsqSqgl(dataWgWgsqSqgl);
    }

    /**
     * 修改网格社区管户
     * 
     * @param dataWgWgsqSqgl 网格社区管户
     * @return 结果
     */
    @Override
    public int updateDataWgWgsqSqgl(DataWgWgsqSqgl dataWgWgsqSqgl)
    {
        dataWgWgsqSqgl.setUpdateTime(DateUtils.getNowDate());
        return dataWgWgsqSqglMapper.updateDataWgWgsqSqgl(dataWgWgsqSqgl);
    }

    /**
     * 批量删除网格社区管户
     * 
     * @param ids 需要删除的网格社区管户ID
     * @return 结果
     */
    @Override
    public int deleteDataWgWgsqSqglByIds(String[] ids)
    {
        return dataWgWgsqSqglMapper.deleteDataWgWgsqSqglByIds(ids);
    }

    /**
     * 删除网格社区管户信息
     * 
     * @param id 网格社区管户ID
     * @return 结果
     */
    @Override
    public int deleteDataWgWgsqSqglById(String id)
    {
        return dataWgWgsqSqglMapper.deleteDataWgWgsqSqglById(id);
    }

    @Override
    public List<DataWgWgsqSqgl> selectDataWgWgsqList(DataWgWgsqSqgl dataWgWgsqSqgl, LoginUser userInfo) {
        List<DataWgWgsqSqgl> list = new ArrayList<>();
        String orgId = userInfo.getSysUser().getDept().getOrgId();
        String userId = userInfo.getSysUser().getUserName();
        //如果是admin用户不做处理 不是管理员或总行的根据机构号查询
//        if(userInfo.getRoles().contains("zhhz")){
//            dataWgWgsqSqgl.setOrgId(orgId);
//        } else if(userInfo.getRoles().contains("common")){
//            dataWgWgsqSqgl.setOrgId(orgId);
//        }

        //	 * type  1社区 2小区
        if ("1".equals(dataWgWgsqSqgl.getType())) {
            list = dataWgWgsqSqglMapper.selectSq(dataWgWgsqSqgl);
        } else if ("2".equals(dataWgWgsqSqgl.getType())) {

            list = dataWgWgsqSqglMapper.selectXq(dataWgWgsqSqgl);
        }
        return list;
    }
}
